package com.tao.service.brand;

import com.github.pagehelper.PageHelper;
import com.tao.dao.BrandMapper;
import com.tao.pojo.Brand;
import com.tao.pojo.BrandExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements IbrandService {
	@Autowired
	BrandMapper brandMapper;

	@Override
	public int add(Brand brand) {
		return brandMapper.insertSelective(brand);
	}

	@Override
	public List<Brand> query(Brand brand,BrandExample example) {
		// TODO Auto-generated method stub
		if(brand.getWithPage()==1)
			PageHelper.startPage(brand.getPageNo(), brand.getPageSize());
		return brandMapper.selectByExample(example);
	}

	@Override
	public int del(Integer id) {
		Brand brand = new Brand();
		brand.setId(id);
		brand.setIsDel(1);
		return brandMapper.updateByPrimaryKeySelective(brand);
		
	}

	@Override
	public int update(Brand brand) {
		return brandMapper.updateByPrimaryKeySelective(brand);
	}

	@Override
	public Brand getBrandById(Integer id) {
		return brandMapper.selectByPrimaryKey(id);
	}

	@Override
	public int undel(Integer id) {
		Brand brand = new Brand();
		brand.setId(id);
		brand.setIsDel(0);
		return brandMapper.updateByPrimaryKeySelective(brand);
	}
	
}